package school.valon.rest.services;

import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import school.valon.business.PaymentBusiness;
import school.valon.dto.ExpensePaymentDto;
import school.valon.dto.PaymentDto;

@Path("/payments")
@PermitAll
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class PaymentService {
	@Autowired()
	@Qualifier("paymentBusiness")
	private PaymentBusiness paymentBusiness;

	@POST
	@RolesAllowed("user")
	public Response makePayment(PaymentDto paymentDto) throws Exception {
		PaymentDto newPaymentDto
			= paymentBusiness.makePayment(paymentDto);
		return Response.status(Response.Status.CREATED).entity(newPaymentDto).build();
	}

	@POST
	@Path("/expenses")
	@RolesAllowed({"user"})
	public Response makeExpensePayment(ExpensePaymentDto expensePaymentDto) throws Exception {
		ExpensePaymentDto newExpensePaymentDto =
				paymentBusiness.makeExpensePayment(expensePaymentDto);
		return Response.status(Response.Status.CREATED).entity(newExpensePaymentDto).build();
	}

}
